package scala.for_the.impatient

import scala.io.Source

/**
  * Created by shichen on 2017/5/31.
  */
object ch09_file {
  val f = Source.fromFile("target/redis-info.txt")

  def main(args: Array[String]): Unit = {
    t2()
  }

  def t3(): Unit = {
    val contents = f.mkString //全部读取
    val ele = contents.split("\\r\\n")
    //printf("%s,%s",ele(0),ele(1))

  }

  def t1(): Unit = {
    val f = Source.fromFile("target/redis-info.txt")
    val lineIterator = f.getLines() //返回一个迭代器，可逐条处理行
    for (l <- lineIterator) {
      println(s"## $l")
    }

    val lines = lineIterator.toArray
    assert(lines.length == 0)

  }

  def t2(): Unit = {
    val f = Source.fromFile("target/redis-info.txt")
    val lines = f.getLines().toArray //转换成Array[String]
    for (l <- lines if l.length != 0) {
      if (!l(0).equals('#')){
        //println("l(0)=" + l(0))
        println(s"l=$l")
      }
    }
  }
}
